const express = require('express')
const router = express.Router()

// 挂载路由

// 导入路由处理函数模块
const dynamic_handler = require('../router_handler/dynamic')

// 处理图片文件中间件
const multer = require('multer')
const path = require('path')

// 创建 multer 的实例对象
const storage = multer.diskStorage({
    destination: (req , file , cb )=>{
        cb(null , path.join(__dirname , '../uploads'));
    },
    filename: function (req, file, cb) {
        cb(null, Date.now() + '-' + file.originalname)
    }
})

const upload = multer({storage: storage})

// 上传-动态封面
router.post('/add/cover', upload.single('file'), dynamic_handler.addCover)

// 增加-新动态
router.post('/add', dynamic_handler.addNew)

// 获取-新动态
router.post('/getMic', dynamic_handler.getMic)

// 删除-新动态
router.delete('/deleteMic/:target', dynamic_handler.deleteMic)

// 获取-指定用户动态
router.post('/postUserMic', dynamic_handler.postUserMic)

// 获取-指定用户点赞动态
router.post('/postUserLikedMic', dynamic_handler.postUserLikedMic)


// 点赞
router.post('/addLike', dynamic_handler.addLike)

// 取消点赞
router.delete('/deleteLike/:target', dynamic_handler.deleteLike)

module.exports = router
